﻿using MESMian.Context;
using MESMian.Test;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MESMian.Forms.DeviceSpec
{
    public partial class DeviceSpecDetail : DetailBase
    {
        public DeviceSpecDetail(int primaryId) : base(primaryId)
        {
            InitializeComponent();
            Load += DeviceSpecDetail_Load;
        }

        private void DeviceSpecDetail_Load(object? sender, EventArgs e)
        {
            Text = "设备规范-详情";
            using (var mtx = new MyContext())
            {
                var model = mtx.DeviceSpecs.Find(primaryId);
                if (model != null)
                {
                    lblDeviceSpecId.Text = model.DeviceSpecId.ToString();
                    lblDeviceSpecName.Text = model.DeviceSpecName.ToString();
                    lblStatus.Text = model.Status == 0 ? "正常" : "禁用";
                    lblStatus.ForeColor = model.Status == 0 ? Color.Black : Color.Red;
                    var userModel1 = mtx.Users.Find(model.CreateUserId);
                    if (userModel1 != null)
                    {
                        lblCreateUserName.Text = userModel1.UserName;
                    }
                    lblCreateTime.Text = model.CreateTime.ToString("yyyy-mm-dd HH:mm");
                    if (model.LastUpdateUserId != null)
                    {
                        var userModel2 = mtx.Users.Find(model.LastUpdateUserId);
                        if (userModel2 != null)
                        {
                            lblLastUpdateUserName.Text = userModel2.UserName;
                        }
                    }
                    else
                    {
                        lblLastUpdateUserName.Text = "无";
                    }
                    if (model.LastUpdateTime != null)
                    {

                        lblLastUpdateTime.Text = ((DateTime)model.LastUpdateTime).ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                    {
                        lblLastUpdateTime.Text = "无";
                    }
                }

            }
        }
    }
}
